<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.util.*,vo.*,utils.*" errorPage="" %>
<%
	TblCustomer tc=(TblCustomer)request.getAttribute("Customer");	
	if(tc==null){
		out.print("Error,can't get infomation about customer!");
		return;
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>为客户添加产品</title>
<LINK rel="stylesheet" href="/css/arg.css" type="text/css">
<style type="text/css">
		@import "/dojo/dijit/themes/tundra/tundra.css";		
	</style>


	<script type="text/javascript" src="/dojo/dojo/dojo.js"
		djConfig="parseOnLoad: true, isDebug: false"></script>
	
	<script language="JavaScript" type="text/javascript">
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dijit.Tree");
		dojo.require("holly.tree.LazyLoadJSIStore");
		dojo.require("dojo.parser");	// scan page for widgets and instantiate them
	</script>
<SCRIPT language="javascript" src="/script/tools_1.js"></SCRIPT>

<script>

function addProduct(pid){
	//alert(pid);
	form1.productId.value=pid.substring(2);
	form1.action="/ProductAction.sn?cmd=addCustomerProduct";
	form1.submit();

}
function delProduct(pid){
	//if(!confirm("确认要删除么"))return;
	form1.productId.value=pid;
	form1.action="/ProductAction.sn?cmd=delCustomerProduct";
	form1.submit();
}
function editProduct(pid,rowid){
	form1.type.value=(prompt("请输入产品类型","产品类型"));
	form1.price.value=prompt("请输入参考价格","0");
	form1.productId.value=pid;
	form1.action="/ProductAction.sn?cmd=addCustomerProduct";
	form1.submit();
}

function backPage(){
	window.location="/CustomerAction.sn?cmd=queryCustomer";

}

</script>
</head>

<body class="tundra">
<form name="form1" method="post" action="" target="frm1">
<table border="1" width="100%" height="100%">
	<tr>
		<td width="50%" valign="top" height="100%"><div id="showList">
			<table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
				<tr><td class="table_item" width=75 >客户名称</td>
				<td class="table_content"><%=tc.getName()%></td>
				</tr>
				<tr><td class="table_item">操作</td>
				<td class="table_content"><input type="button" class="button" value="返回" onClick="backPage()" /></td>
				</tr>
			</table>
			<script>createTitle("客户的产品列表");</script>
			<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="seachlist">
				<thead>
				  <tr class="seachlist">
					<th >产品名称</th>					
					<th >产品类型</th>
					<th >参考价格</th>
					<th>操作</th>
				  </tr>
				</thead>
				<tbody>
				<%
				List list=(List)request.getAttribute("result");
				if(list!=null){
					TblCustomerProduct tcp;
					for(int i=0;i<list.size();i++){
						tcp=(TblCustomerProduct)list.get(i);
						%>
						<tr class="seachlist_td1">
							<td><%=BussUtil.getNameById("name","Product","id",tcp.getId().getProductId()+"")%></td>
							<td><%=HtmlUtil.noNull(tcp.getType())%></td>
							<td><%=HtmlUtil.noNull(tcp.getPrice())%></td>		
							<td><a href="javascript:editProduct(<%=tcp.getId().getProductId()%>)"><img src="/images/cmdEdit.gif" />修改</a>&nbsp;&nbsp;
								<a href="javascript:delProduct(<%=tcp.getId().getProductId()%>)"><img src="/images/cmdDel.gif" />删除</a>
						</tr>
						<%					
					}				
				}
				%>
				</tbody>
			</table>
			</div>
		</td>
		<td width="50%" valign="top">
			<script>createTitle("选择产品")</script>
			<table width="100%" border="0" cellpadding="3" cellspacing="0" class="border" height="100%">
			  <tr>    
				<td class="table_content" valign="top">
				<div dojoType="holly.tree.LazyLoadJSIStore" url="/TreeAction.sn?cmd=getNode" jsid="continentStore"></div>
				
				<div dojoType="dijit.Tree" id="mytree" store="continentStore" query="{type:'root'}" label="根目录" persist="false">
					<script type="dojo/method" event="onClick" args="item">
						if(item){
//							alert("Execute of node " + continentStore.getLabel(item)
//								+", population=" + continentStore.getValue(item, "id"));
							if(continentStore.getValue(item,"leaf")=="1"){
								addProduct(continentStore.getValue(item,"objectId"));
							}

						}else{
							//alert("Execute on root node");
						}
					</script>
					<script type="dojo/method" event="mayHaveChildren" args="item">
						try{
							if(continentStore.getValue(item,"leaf")=="1")						
								return false;
							else
								return true;
						}catch(e){}
					</script>
				</div>
				</td>
			</table>
		</td>
	</tr>
</table>
<input type="hidden" name="type" />
<input type="hidden" name="price" />
<input type="hidden" name="productId" value="" />
<input type="hidden" name="customerId" value="<%=tc.getId()%>" />
</form>
<iframe id="frm1" name="frm1" width="0"></iframe>
</body>
</html>
